<?php
class Manage_moduleAction extends CommonAction {
    public function index(){
		$this->listmap=1;
		
		
		if($this->_get('tablename')){
			$this->listmap .= " and tablename='".$this->_get('tablename')."'";
			
			$this->_list();
			$this->display('index1');
		}else{
			$this->list = $this->dao->group('tablename')->select();
			$this->display();
		}
	}
	
	
	
	public function edit(){
		$this->alltables = $this->dao->getAllTables();
		$this->group_list=M('Setting_group')->select();
		parent::edit();
	}
	
	
	public function getFields(){
		if($this->_post('tablename')){
			$this->list = M() ->table($this->_post('tablename')) -> getDbFields();
			$exl = array();
			$elist = $this->dao->where(array('tablename' => $this->_post('tablename')))->select();
			foreach($elist as $k=>$v){
				$exl[] = $v['fieldname'];
			}
			$this->exl = $exl;
			echo $this->fetch('fieldlist');
		}
	}
	/*public function update(){
		if(isset($_POST)){
			$db=M('Setting');
			foreach($_POST as $k=>$v){
			    $db->where(array('name'=>$k))->save(array('val'=>$v));
			}
			$this->success('保置成功!',U('Setting/index'));
		}
	}*/
	//添加方法重写
	public function add(){
		$this->alltables = $this->dao->getAllTables();
		$this->group_list=M('Setting_group')->select();
		parent::add();
	}
	
	
	//生成模板配置列表
	public function createConfList(){
		if($this->_post('ids')){
			$s=array();
			$setting_list=M('Setting_group')->order('sort')->select();
			foreach($setting_list as $k=>$v){
				$_select=$this->dao->where(array('group_id'=>$v['id'],'id'=>array('in',$this->_post('ids'))))->order('sort')->select();
				foreach($_select as $kk=>$vv){
					$_select[$kk]['_select']=json_decode($vv['_select'],true);
				}//dump($_select);
				$setting_list[$k]['list']=$_select;
				if(empty($_select)){
					unset($setting_list[$k]);
				}else{
				    $s[]=$setting_list[$k];
				}
			}
			echo JSON($s);
		}
	}
}
?>